﻿@using ThuySan.Areas.Backend.Models
@using ThuySan.Models
@model IEnumerable<dynamic>
@{
    Layout = "~/Areas/Backend/Views/Shared/_Layout.cshtml";
    Header header = new Header
    {
        Common = "ViewUserControl_Banner_Index",
        PageHeader = "Quản lý Banner",
        Menulv1 = "02",
        Menulv2 = "0204"
    };
    ViewData[Header.Key] = header;
    ViewBag.Title = "Manage Banner - Admin Control Panel";
}
@Html.Telerik().Grid(Model).Name("grid").Columns(c =>
                                                     {
                                                         c.Bound(typeof(int), "Id").Title("ID").Width(50);
                                                         c.Bound("ImageName").Filterable(false).Title("").Width(100).ClientTemplate("<img width=\"80\" src=\"" + Html.UploadPath("Products") + "80x80_<#=ImageName#>\" title=\"<#=Description#>\"/>");
                                                         c.Bound(typeof(string), "Description").Title("Chú thích");
                                                         c.Bound(typeof(int), "Priority").Title("Độ ưu tiên ");
                                                         c.Bound("IsBanner").Filterable(false)
                                                             .ClientTemplate("<input <#= IsBanner #> class=\"check-box\" disabled=\"disabled\" type=\"checkbox\" />").Title("Là Banner");
                                                         c.Template(v => v.ProductId).ClientTemplate(Html.ActionLink("<span class=\"t-icon t-edit\"></span>", "Edit", new
                                                         {
                                                             id = "<#=Id#>"
                                                         }, new
                                                         {
                                                             @class = "t-button t-button-icon t-grid-edit",
                                                         }).ToHtmlString() + "<a class=\"t-button t-button-icon t-grid-delete\" href=\"javascript:Delete(<#=Id#>);\"><span class=\"t-icon t-delete\"></span></a>").Width(80);
                                                     }).Sortable(c => c.Enabled(true)).Filterable().DataKeys(c => c.Add("Id")).ToolBar(v => v.Custom().ButtonType(GridButtonType.Text).Text("Thêm Banner").HtmlAttributes(new
                                                     {
                                                         href = Url.Action("Add")
                                                     })).Pageable(c =>
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                         c.Enabled(true);
                                                                                                                                                                                                                                         c.PageSize(25);
                                                                                                                                                                                                                                     }).DataBinding(c => c.Ajax().Select("GetList", "Banner", new
                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                         ViewBag.Id
                                                                                                                                                                                                                                     }))
@section script
{
    <script type="text/javascript">
        function Delete(id) {
            if (confirm("Bạn muốn xóa banner này?"))
                $.post('@Url.Action("Delete", "Banner")', { id: id }, function (data) {
                    ShowNotification(data);
                    $("#grid").data("tGrid").ajaxRequest();
                });
        }
    </script>
}
